define([

], function () {

    var SessionModel = Backbone.Model.extend({
        isConnected: function () {
            return (__currentToken != "" && __currentSession != "");
        },
        connect: function (user, pass, company, callbackOk, callbackError) {


            var options = {
                error: function (jqXHR, textStatus, errorThrown) {
                    alert("Could not contact server " + __apiURL);
                },
            }

            send("security/login", { user: user, password: pass, companyId: company }, options, function (data) {
                if (data.result == 1) {
                    __currentToken = data.session.token;
                    __currentSession = data.session;
                    setProcessDictionary(data.session.process);
                    ajaxSetup();
                    callbackOk(data);
                }
                else {
                    callbackError(data.result);
                }
            });
        },
        getUserCompanies: function (user, pass, callback) {
            send("security/getUserCompanies", { user: user, password: pass }, null, function (data) {
                callback(data);
            });
        },
        logout: function (callback) {
            send("security/logout", null, null, function (data) {
                if (callback != undefined)
                    callback(data);
            });
        },
        getAllSessions: function (callbackOk) {
            send("security/getAllSessions", null, null, callbackOk);
        },
        getAllProcess: function (callbackOk) {
            send("security/getAllProcess", null, null, callbackOk);
        }
    });
    return SessionModel;
});